<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <title>Bing每日图片API接口演示</title>
    <meta name="keywords" content="获取必应每日壁纸" />
    <meta name="description" content="获取必应每日壁纸" />
    <link rel="stylesheet" type="text/css" href="/css/main.min.css" />
    <link rel="stylesheet" type="text/css" href="/css/ashes.min.css" />
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
            max-width: 600px;
            width: 100%;
        }
        .image-container {
            margin: 20px 0;
        }
        .image-container img {
            max-width: 100%;
            border-radius: 8px;
        }
        .loading {
            display: none;
            font-size: 16px;
            color: #007bff;
        }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>Bing每日图片</h1>
    <div class="image-container" id="image-container">
        <p>点击下面的按钮来获取必应每日壁纸。</p>
    </div>
    <div class="loading" id="loading">加载中，请稍候...</div>
    <button id="getImageButton">获取图片</button>
</div>

<script>
    document.getElementById('getImageButton').addEventListener('click', function() {
        const loadingDiv = document.getElementById('loading');
        const imageContainer = document.getElementById('image-container');

        // 显示加载提示
        loadingDiv.style.display = 'block';
        imageContainer.innerHTML = '';

        fetch('https://api.vvhan.com/api/bing?size=640x480&type=json')
            .then(response => response.json())
            .then(data => {
                // 隐藏加载提示
                loadingDiv.style.display = 'none';

                if (data.data.url) {
                    imageContainer.innerHTML = `<img src="${data.data.url}" alt="Bing每日图片" />`;
                } else {
                    imageContainer.innerText = '获取图片失败，请稍后再试。';
                }
            })
            .catch(error => {
                console.error('Error fetching the image:', error);
                loadingDiv.style.display = 'none';
                imageContainer.innerText = '获取图片失败，请稍后再试。';
            });
    });
</script>
</body>
</html>
